/*公用方法区域*/

//拦截所有post请求 这两句不需要
// Mock.mock(/\.json/, 'post', function (options) {
//   return options
// })


//AJAX post数据通用方法范例
function ajaxPost(url) {
  var robot = $('.monitor .robot button > .filter-option').text();
  var startTime = document.getElementById('monitorStartTime').value;
  var endTime = document.getElementById('monitorEndTime').value;
  var notifier = $('.monitor .notifier button > .filter-option').text();
  //	notifier =  encodeURI(encodeURI(notifier));
  //	console.log(robot);
  $.ajax({
    url: url,
    type: "post",
    dataType: "json",
    contentType: 'text/json,charset=utf-8',
    data: {
      robot: robot,
      startTime: startTime,
      endTime: endTime,
      notifier: notifier
    },
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log(decodeURI(JSON.stringify(data, null, 2)));
    }
  })
}

//slide通用渲染方法
function startSlide(dom, num) {
  jQuery(dom).slide({
    titCell: ".hd ul",
    mainCell: ".bd ul",
    autoPage: false,
    effect: "left",
    autoPlay: true,
    vis: num
  });
}

//分页控件通用渲染方法
function startPaginator(dom, total, p, fn) {
  $.jqPaginator(dom, {
    totalPages: total,
    visiblePages: 10,
    currentPage: 1,
    first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
    prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
    next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
    last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
    page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
    onPageChange: function (num) {
      fn(num, p);
    }
  });
}

//选择机器人下拉框初始化
$('.pickRobot').selectpicker({
  title: '选择机器人',
  style: 'btn-info',
  size: 4
});

//移动到指定区域下拉框初始化
$('.moveArea').selectpicker({
  title: '移动到指定区域',
  style: 'btn-info',
  size: 4
});

//选择任务下拉框初始化
$('.pickTask').selectpicker({
  title: '选择任务',
  style: 'btn-info',
  size: 4
});

//选择预约人下拉框初始化
$('.pickBookingPerson').selectpicker({
  title: '选择预约人',
  style: 'btn-info',
  size: 4
});

//选择状态下拉框初始化
$('.pickState').selectpicker({
  title: '选择状态',
  style: 'btn-info',
  size: 5
});

//选择通知人下拉框初始化
$('.pickNotifier').selectpicker({
  title: '选择联系人',
  style: 'btn-info',
  size: 4
});

//选择部门类型下拉框初始化
$('.pickDepartment').selectpicker({
  title: '部门类型',
  style: 'btn-info',
  size: 4
});

//选择最低电量
$('.pickEnergy').selectpicker({
  style: 'btn-info',
  size: 4
});

//选择权限管理人员下拉框初始化
$('.pickAdmin').selectpicker({
  title: '请选择',
  style: 'btn-info',
  size: 4
});

//选择排序下拉框初始化
$('.pickSort').selectpicker({
  title: '请选择排序顺序',
  style: 'btn-info',
  size: 4
});

//日期控件初始化，精确到5分钟
$('.datetimepicker').datetimepicker({
  format: 'yyyy-mm-dd hh:ii',
  language: 'zh-CN',
  weekStart: 1,
  todayBtn: true,
  autoclose: 1,
  todayHighlight: true,
  startView: 2,
  minView: 0, //日期时间选择器所能够提供的最精确的时间选择视图。
  forceParse: 0
});

//日期控件初始化，精确到月份
$('.datetimepickerMonth').datetimepicker({
  format: 'yyyy-mm',
  language: 'zh-CN',
  weekStart: 1,
  todayBtn: true,
  autoclose: 1,
  todayHighlight: true,
  startView: 2,
  minView: 2, //日期时间选择器所能够提供的最精确的时间选择视图。
  forceParse: 0
});

//日期控件初始化，精确到月份
$('.datetimepickerDay').datetimepicker({
  format: 'yyyy-mm-dd',
  language: 'zh-CN',
  weekStart: 1,
  todayBtn: true,
  autoclose: 1,
  todayHighlight: true,
  startView: 2,
  minView: 1, //日期时间选择器所能够提供的最精确的时间选择视图。
  forceParse: 0
});

//返回固定格式的现在时间
function date() {
  var date = new Date();
  var year = date.getFullYear();
  var month = date.getMonth() + 1; //js从0开始取 
  var date1 = date.getDate();
  var hour = date.getHours();
  var minutes = date.getMinutes();
  var second = date.getSeconds();
  //	console.log(year + "年" + month + "月" + date1 + "日" + hour + "时" + minutes + "分" + second + "秒");
  var formatDate;
  formatDate = year + '-' + month + '-' + date1 + ' ' + hour + ':' + minutes;
  return formatDate;
}

//切换到tableDiv里的启用button，点击切换启用状态
$('.tableDiv tbody').on('click', 'td.initiate button', function () {
  $(this).toggleClass('active');
});

/*AJAX数据加载方法↓*/

//获取展厅列表
function getExhibitionhallList() {
  var data = {
    content: {
      pageNum: 1,
      pageSize: 10
    }
  };
  data = JSON.stringify(data);

  $.ajax({
    type: "POST",
    url: api.exhibitionhall_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: data,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log(data, '展厅列表');

      var result = JSON.parse(data);
      //目前获取的是二层的展厅
      var list = result.content.list;

      console.log(list[0].exhibitionhallId, 'list');

      exhibitionhall2 = list[0];

    }
  })
}

//首页，实时监控 ， 机器人位置AJAX
function ajaxRobotPosition() {

  var robotId = $('.control .pickRobot option:selected').val() || 1; //机器人ID 默认小威

  var p = {
    content: {
      robotId: robotId
    }
  }
  p = JSON.stringify(p);
  
  $.ajax({
    type: "post",
    url: api.robot_position,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
    error: function (xhr) {
      alert('無法取得資料');
      clearInterval(window.robotPoisitionInterval);
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      console.log('==================================');
      console.log(data);

      // 返回数据为竖屏坐标数据
      var coordinate = data.content;
      var heightPercent = coordinate.x/planHeight + '%';
      var widthPercent = coordinate.y/planWidth + '%';

      var $robot = $('#icon-robot');
      $robot.css({
        'top': widthPercent,
        'left': heightPercent
      })
    }
  });
}

// 实时监控，机器人方向控制
function ajaxRobotAction(direction){
	// direction 0-暂停 1-前进 2-后退 3-左转 4-右转 详见API文档

	var robotId = $('.control .pickRobot option:selected').val();
	var p = {
		content: {
			robotId:robotId,
			action: direction
		}
	}
  p = JSON.stringify(p);

	$.ajax({
		type: "post",
		url: api.robot_control_direction,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
			console.log(data);
		}
	});
}

// 实时监控，前置摄像头
function ajaxRobotCamera(isOpen){
  // isOpen 1-开启，0-关闭

  var robotId = $('.control .pickRobot option:selected').val() || 1;//机器人ID 默认小威

  var p = {
    content: {
      robotId: robotId,
      isOpen: isOpen
    }
  }
  p = JSON.stringify(p);

  $.ajax({
		type: "post",
		url: api.robot_camera,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      
			console.log(data);
		}
	});
}

// 实时监控，切换后台语音
function ajaxToggleVoice(){
  $.ajax({
		type: "post",
		url: api.robot_voice,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
			console.log(data);
		}
	});
}

// 实时监控，加载指定区域
function ajaxAppointPosition(){

  var exhibitionhallId = 1;//默认先用二层的展厅id

  var p = {
    content: {
      exhibitionhallId: exhibitionhallId
    }
  }
  p = JSON.stringify(p);

  $.ajax({
		type: "post",
		url: api.robot_appoint_list,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      
      var result = JSON.parse(data);
      var list = result.content.list;
      // 实时监控 --> 移动区域选择框
      var ap = '';
      ap += '<select class="selectpicker show-tick form-control pickAppoint" onchange="controlAppointPosition(this)">';
      for (let i = 0; i < list.length; i++) {
        ap += '<option value=' + list[i].productId + '>' + list[i].productName + '</option>';
      }
      ap += '</select>'
      $('.control .pickAppoint').html(ap);
      $('.control .pickAppoint').selectpicker({
        title: '移动到指定区域',
        style: 'btn-info',
        size: 4
      })
		}
	});
}

// 实时监控，加载任务列表
function ajaxTask(){

  var productId = $('.control .pickAppoint option:selected').val();

  var p = {
    content: {
      productId: productId
    }
  }
  p = JSON.stringify(p);

  $.ajax({
		type: "post",
		url: api.robot_task_list,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      console.log('========================================\n');
      console.log(data);
      
      var result = JSON.parse(data);
      var list = result.content.list;
      // 实时监控 --> 任务选择框
      var task = '';
      task += '<select class="selectpicker show-tick form-control pickTask">';
      for (let i = 0; i < list.length; i++) {
        task += '<option value= ' + list[i].pointPosition + '>' + list[i].plateName + '</option>';
      }
      task += '</select>'
      $('.control .pickTask').html(task);
      $('.control .pickTask').selectpicker({
        title: '选择任务',
        style: 'btn-info',
        size: 4
      })
		}
	});
}

// 实时监控，跳转任务
function ajaxTurnTask() {
  
  var robotId = $('.control .pickRobot option:selected').val() || 1; //机器人ID 默认小威
  var point = $('.control .pickTask option:selected').val();

  var p = {
    content: {
      robotId: robotId,
      point: point
    }
  }
  p = JSON.stringify(p);

  $.ajax({
		type: "post",
		url: api.robot_turn_task,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      console.log('========================================');

      var result = JSON.parse(data);
      
      if(result.respCode != '0000'){
        alert(result.respMsg.split('<br/>').join('\n'));
      }
      
      var list = result.content.list;
		}
	});
}

//实时监控，右上文本数据AJAX
function ajaxRobotText() {
  $.ajax({
    type: "get",
    url: "control.json",
    async: true,
    dataType: 'json',
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      $('.control .expository .content').html(data.robot);
    }
  });
}

//实时监控，左下文本数据AJAX(机器人当前命令)
function ajaxCurrentOrder() {

  var robotId = $('.control .pickRobot option:selected').val() || 1; //机器人ID 默认小威
  
  var p = {
    content: {
      robotId: robotId
    }
  }
  p = JSON.stringify(p);
  console.log(p);
  
  $.ajax({
    type: "post",
    url: api.robot_current_order,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);
      console.log('current_order=========================');
      
      console.log(result);
      if(result.respCode == '0001'){
        console.log('当前命令无数据');
        $('.control .txtMarquee-top .bd-left').html('无当前命令');
        $('.control .txtMarquee-top .bd-right').html('无接待人员信息');
        return;
      }
      
      $('.control .expositoryPic .content').html(result.content.processInfo.explainContent);
      $('.control .txtMarquee-top .bd-left').html(result.content.processInfo.plateName);
      $('.control .txtMarquee-top .bd-right').html(result.content.reservationInfo);
    }
  });
}

//实时监控，右下表格数据AJAX(前5条命令列表)
function ajaxRobotOrderSubList() {

  var robotId = $('.control .pickRobot option:selected').val() || 1; //机器人ID 默认小威
  
  var p = {
    content: {
      robotId: robotId,
      pageNum: 1,
      pageSize: 5
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_order_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      var result = JSON.parse(data);
      if(result.respCode != '0000'){
        alert(result.respMsg.split('<br/>').join('\n'));
        return;
      }
      var list = result.content.list;
      var jg = '';
      for (var i = 0; i < 4 && i<list.length; i++) {
        jg += '<tr>';
        jg += '<td>' + (i+1) + '</td>';
        jg += '<td>' + list[i].processType + '</td>';
        jg += '<td>' + list[i].plateName + '</td>';
        jg += '<td>' + list[i].productName + '</td>';
        jg += '<td>' + list[i].result + '</td>';
        jg += '<td>' + list[i].feedback + '</td>';
        jg += '</tr>';
      }
      $('.controlTable tbody').html(jg);
    }
  });
}

//实时监控，弹窗表格数据，初始化AJAX
function initRobotOrderList(parameter) {

  var robotId = $('.control .pickRobot option:selected').val() || 1; //机器人ID 默认小威

  var p = {
    content: {
      pageNum: 1,
      robotId: robotId
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_order_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      var result = JSON.parse(data);

      var dom = $('.controlMoreModal .pagination');
      if (result.content.pages<1) {
        $('.controlModalTable tbody').html('');
        return;
      }
      startPaginator(dom, result.content.pages, parameter, ajaxRobotOrderList);
    }
  });
}

//实时监控，弹窗表格数据AJAX
function ajaxRobotOrderList(pageNum) {

  var robotId = $().val();

  var p = {
    content: {
      robotId: robotId
    }
  }
  p = JSON.stringify(p);
  
  $.ajax({
    type: "get",
    url: "control.json",
    async: true,
    dataType: 'json',
    data: {
      currentPage: pageNum,
    },
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);
      if(result.respCode != '0000'){
        alert(result.respMsg.split('<br/>').join('\n'));
        return;
      }
      var list = result.content.list;
      var len;
      if (list.length >= 15) {
        len = 15;
      } else {
        len = list.length;
      }
      var jg = '';
      for (var i = 0; i < len; i++) {
        jg += '<tr>';
        jg += '<td>' + (i+1) + '</td>';
        jg += '<td>' + list[i].processType + '</td>';
        jg += '<td>' + list[i].plateName + '</td>';
        jg += '<td>' + list[i].productName + '</td>';
        jg += '<td>' + list[i].result + '</td>';
        jg += '<td>' + list[i].feedback + '</td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.controlModalTable tbody').html(jg);
    }
  });
}
//配置管理/预约管理→获取机器人列表
function getRobotsList() {


  var exhibitionhallId = 1;

  if (exhibitionhall2 != null && exhibitionhall2 != undefined) {

    exhibitionhallId = exhibitionhall2.exhibitionhallId
  }

  var data = {
    content: {
      exhibitionhallId: exhibitionhallId
    }
  };
  data = JSON.stringify(data);

  $.ajax({
    type: "POST",
    url: api.robot_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: data,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log(data, '机器人列表');

      var result = JSON.parse(data);
      //
      var list = result.content.list;

      robot_list = list;

      var len;
      len = list.length;

      var jg = '';

      jg += '<select class="selectpicker show-tick form-control pickRobot">';

      for (var i = 0; i < len; i++) {

        jg += '<option value= ' + list[i].id + '>' + list[i].robotName + '</option>';
      }
      jg += '</select>';

      $('.appointment .showTable .sel .dropdown:nth-child(1)').html(jg);

      //模态框（预约管理/权限管理）--》机器人选择
      $('.modal .form-row .dropdown:nth-child(1)').html(jg);


      //编辑权限管理
      $('#permissEdit .permissEditRobot').html(jg);

      //监测预警 --》 机器人选择
      $('.monitor .pickRobot').html(jg);

      //实时监控 --》 机器人选择
      $('.control .pickRobot').html(jg);
      $('.control .pickRobot').on('change',controlPickRobot);

      //配置管理界面 change
      var pz = '';
      pz += '<select class="selectpicker show-tick form-control pickRobot" onchange="pz_selectOnchang(this)">';
      for (var i = 0; i < len; i++) {

        pz += '<option value= ' + list[i].id + '>' + list[i].robotName + '</option>';
      }
      pz += '</select>';

      $('.settings .setting-pickRobot').html(pz);


      //下拉框初始化
      $('.pickRobot').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });

      // $('.modal .pickRobot').html(jg);

    }
  })

}

//配置管理→系统配置→机器人负责人配置，初始化AJAX
function initPersonCharge(parameter) {

  var obj = parameter;
  obj.pageNum = 1;
  var p = {
    content: obj
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "POST",
    url: api.responsibleperson_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('initPersonCharge', result.content.total, result);

      if (result.content.pages < 1) return;
      var dom = $('.personCharge .pagination');

      startPaginator(dom, result.content.pages, parameter, ajaxPersonCharge);
    }
  });
}

//配置管理→系统配置→机器人负责人配置,AJAX
function ajaxPersonCharge(pageNum, parameter) {
  var obj = parameter;
  obj.pageNum = pageNum;

  var p = {
    content: obj
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.responsibleperson_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      responsibleperson_list = result.content.list;

      console.log('配置管理→系统配置→机器人负责人配置', result);
      var list = result.content.list;

      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      var len = list.length;
      for (var i = 0; i < len; i++) {
        var num = i + 1;
        var right = list[i].right;
        if (right == 1) {
          jg += '<tr class="mainPerson">';
        } else {
          jg += '<tr>';
        };
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].personName + '</td>';
        jg += '<td>' + list[i].personPhone + '</td>';
        jg += '<td>' + list[i].personEmail + '</td>';
        if (right == 1) {
          jg += '<td>主负责人</td>';
        } else {
          jg += '<td>辅助负责人</td>';
        };
        jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        if (right == 1) {
          jg += '<td></td>';
        } else {
          jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        };
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tablePersonCharge tbody').html(jg);
    }
  });
}

//配置管理→系统配置→机器人负责人添加,AJAX
function add_responsibleperson(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.add_responsibleperson,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('添加负责人', data);

      var result = JSON.parse(data);

      //添加成功之后
      var obj = {
        robotId: parameter.robotId
      }

      initPersonCharge(obj);


    }
  })
}
//配置管理→系统配置→机器人负责人更新,AJAX
function updataResponsibleperson(parameter) {
  var p = {
    content: {
      list: parameter
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.update_responsibleperson,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('负责人列表跟新', data);
      var result = JSON.parse(data);

      var obj = {
        robotId: parameter[0].robotId
      }

      initPersonCharge(obj);

    }
  })
}
//配置管理→系统配置→机器人负责人删除,AJAX
function deleteResponsibleperson(parameter) {
  var p = {
    content: {
      ids: parameter.ids
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.delete_responsibleperson,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('删除负责人', data);
      var result = JSON.parse(data);

      var obj = {
        robotId: parameter.robotId
      }

      initPersonCharge(obj);

    }
  })

}
//配置管理→系统配置→机器人形象库,AJAX
function ajaxImage(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.image_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      console.log('机器人形象库', data);
      var result = JSON.parse(data);

      robotImage_list = result.content.list;
      var list = result.content.list;

      var jg = '';
      var len = list.length + 1;
      for (var i = 0; i < len; i++) {
        if (i != len - 1) {
          if(list[i].isEnable==1){
            jg += '<li class="checked">';
          }else{
            jg += '<li>';
          }        
          jg += '<div>';
          jg += '<div class="pic">';
          jg += '<img src=' + BASEURL + '/file/pic?id=' + list[i].imageFileId + ' />';
          jg += '</div>';
          jg += '<div class="title">' + list[i].imageName + '</div>';
          jg += '</div>';
          jg += '</li>';
        } else {
          jg += '<li class="add">';
          jg += '<div>';
          jg += '<div class="pic"><input type="file" accept="image/*" name="uploadPicture" id="uploadFile" value="" title="上传照片" onchange="getPhoto(this)" style="opacity:0;width:100%;height:100%;background-color:red;"/></div>';
          jg += '<div class="title">添加形象</div>';
          jg += '</div>';
          jg += '</li>';
        }
      }
      //    console.log(jg)  ;
      $('.imageLibrary ul').html(jg);
      dom = $('.imageSlide');
      startSlide(dom, 5);
    }
  });
}
//配置管理→系统配置→机器人形象库,上传机器人新图片,AJAX
function addRobotImage(obj) {

  var p = obj.fileData;

  $.ajax({
    type: "post",
    url: api.add_image,
    async: true,
    dataType: 'json',
    cache: false,//上传文件无需缓存        
		processData: false,//使用于对data参数进行序列化解决 这里必需false         
		contentType: false, //必需
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('上传图片', data);
      // var result = JSON.parse(data);

      var h = {
        robotId: obj.robotId,
        pageNum: 1,
        pageSize: 200
      }
      ajaxImage(h)
    }
  })

}
//配置管理→系统配置→机器人形象库,机器人形象选择,AJAX
function enableRobotImage(obj) {
  var p = {
    content: {
      robotId: obj.robotId,
      imageLibId: obj.id
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_image,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('机器人图片选择', data);
      var result = JSON.parse(data);
      alert('图片设置成功!');
    }
  })
}
//配置管理→系统配置→场馆地图库，AJAX
function ajaxVenue(parameter) {
  var p={
    content: parameter
    }
    p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url:api.exhibitionhall_mapList,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('展厅地图库', data);
      var result = JSON.parse(data);

      exhibitionhall_mapList= result.content.list;
      var list = result.content.list;

      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      var len = list.length + 1;
      for (var i = 0; i < len; i++) {
        if (i != len - 1) {
          if(list[i].isEnable==1){
            jg += '<li class="checked">';
          }else{
            jg += '<li>';
          }
          jg += '<div>';
          jg += '<div class="pic">';
          jg += '<img src=' + BASEURL + '/file/pic?id=' + list[i].mapFileId + ' />';
          jg += '</div>';
          jg += '<div class="title">' + list[i].mapName + '</div>';
          jg += '</div>';
          jg += '</li>';
        } else {
          jg += '<li class="add">';
          jg += '<div>';
          jg += '<div class="pic"><input type="file" accept="image/*" name="uploadPicture" id="uploadMapFile" value="" title="上传照片" onchange="getMapPhoto(this)" style="opacity:0;width:100%;height:100%;background-color:red;"/></div>';
          jg += '<div class="title">添加地图</div>';
          jg += '</div>';
          jg += '</li>';
        }
      }
      //    console.log(jg);
      $('.venueMap ul').html(jg);
      dom = $('.venueSlide');
      startSlide(dom, 5); //渲染slide
    }
  })
}
//配置管理→系统配置→场馆地图库-添加场馆地图，AJAX
function addMap(parameter){
  var p = parameter;

  $.ajax({
    type: "post",
    url: api.add_map,
    async: true,
    dataType: 'json',
    cache: false,//上传文件无需缓存        
		processData: false,//使用于对data参数进行序列化解决 这里必需false         
		contentType: false, //必需
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('上传展厅图片', data);
      // var result = JSON.parse(data);

      var obj = {
        pageNum:1,
        pageSize:100,
        exhibitionhallId:1  //目前默认二层展厅
      }
      ajaxVenue(obj);
    }
  })
}
//配置管理→系统配置→场馆地图库-选择场馆地图，AJAX
function enableMapImage(parameter){
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.enable_map,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('机器人图片选择', data);
      var result = JSON.parse(data);
      alert('场馆图片设置成功!');
    }
  })
}
//配置管理→系统配置→机器人最低电量-，AJAX
function setMinEnergy(parameter){
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.setup_minElectric,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      alert('设置最低电量成功');
      console.log('最低电量', data);
      var result = JSON.parse(data);
      
    }
  })
}
//配置管理→业务配置→板块及展板配置①，AJAX
function ajaxPlate(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.product_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      console.log('板块配置',result);

      plate_list = result.content.list;

      var list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].productName + '</td>';
        if(list[i].backgroundColor==""){
          jg += '<td><input type="color" name="color" id="" value="#ffffff" disabled="disabled" onblur="chkvalue(this)" /></td>';
        }else{
          jg += '<td><input type="color" name="color" id="" value="' + list[i].backgroundColor + '" disabled="disabled" onblur="chkvalue(this)"/></td>';
        }
       
        jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tablePlate tbody').html(jg);
    }
  });
}
//配置管理→业务配置→板块及展板删除①，AJAX
function deleteExhibitionhallProduct(parameter){
  var id = parameter.productId;
  var ary = [];
  ary.push(id);

  var p = {
    content: {
      productIds:ary,
      isPd:1
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.delete_product,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('删除板块', data);
      var result = JSON.parse(data);

      var obj ={
        exhibitionhallId:1,
        pageNum:1,
        pageSize:100
      }
      ajaxPlate(obj);
      
    }
  })



}
function updataProduct(parameter){
  var p = {
    content:parameter
  }
  p = JSON.stringify(p);
  
  $.ajax({
    type: "post",
    url: api.update_product,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('更新板块', data);
      var result = JSON.parse(data);

      alert('修改成功');

      var obj ={
        exhibitionhallId:parameter.exhibitionhallId,
        pageNum:1,
        pageSize:100
      }
      ajaxPlate(obj);
      
    }
  })




}
//配置管理→业务配置→板块及展板配置②，AJAX
function ajaxPanel(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.plate_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('展板配置',result);

      var list = result.content.list;

      pannel_list = result.content.list;
      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        // jg += '<td><input type="" name="" id="" value="' + list[i].productName + '" disabled="disabled"/></td>';
        jg += '<td>'+ list[i].productName + '</td>';
        jg += '<td>' + list[i].plateRemark + '</td>';
        jg += '<td>' + list[i].plateName + '</td>';
        jg += '<td>' + list[i].plateWeight + '</td>';
        // jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      //jg += '<td><input type="color" name="color" id="" value="' + list[i].backgroundColor + '" disabled="disabled" onblur="chkvalue(this)"/></td>';
      $('.tablePanel tbody').html(jg);
    }
  });
}
//配置管理→业务配置→板块及展板配置②--删除，AJAX
function deletePlate(parameter){
  var p = {
    content: {
      plateIds:parameter,
      isPd:1
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.delete_plate,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
      console.log('删除展板',data);
      var result = JSON.parse(data);
      
      var obj ={
        exhibitionhallId:1,
        pageNum:1,
        pageSize:100
      }
      
      ajaxPanel(obj);

    }
    }) 
}
//配置管理→业务配置→板块及展板配置②--编辑更新，AJAX
function updatePlate(parameter){
  var p = {
    content: {
      list:parameter,
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.update_plate,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('更新展板',data);
    var result = JSON.parse(data);

    var obj ={
      exhibitionhallId:1,
      pageNum:1,
      pageSize:100
    }
    
    ajaxPanel(obj);
    }
    }) 


}
//配置管理→业务配置→机器人名称配置，AJAX
function ajaxRobot(parameter) {
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_list_gl,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('机器人名称配置',result);

      var list = result.content.list;

      robot_list_gl = result.content.list;
      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].robotName + '</td>';
        jg += '<td>' + list[i].primaryResponsiblePersonName + '</td>';
        jg += '<td>' + list[i].startUserDate + '</td>';
        jg += '<td>' + list[i].maintainTime + '</td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableRobot tbody').html(jg);
    }
  });
}
//配置管理→业务配置→机器人名称配置--新增机器人，AJAX
function addRobot(parameter){
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.add_robot_gl,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('新增机器人',data);
    var result = JSON.parse(data);

    var obj = {
      exhibitionhallId: 1,//目前选择二层展厅
    }
  
    ajaxRobot(obj);
    }
    }) 
}
/*//配置管理→业务配置→机器人名称配置
var tableRobot = {
	'list|3-8': [{
		'name': '@ctitle(4, 6)',
		'admin|1': ['王某某', '张丽丽', '丁点点'],
		'begin': '@date("yyyy-MM-dd")',
		'end': '@date("yyyy-MM-dd")'
	}]
}
var tableRobot = Mock.mock(/tableRobot.json/, tableRobot);*/

//配置管理→业务配置→讲解词、语言库配置，初始化AJAX
function initCommentary(parameter) {
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.jiangjie_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      
      var result = JSON.parse(data);
      console.log('讲解词',result);
      if(result.content.pages<1){
        $('.tableCommentary tbody').html('');
        return;
      }
      var dom = $('.commentary .pagination');
      startPaginator(dom, result.content.pages,parameter, ajaxCommentary);
    }
  });
}
//配置管理→业务配置→讲解词、语言库配置--上传文件，初始化AJAX
function addJiangjie(parameter){
  var p = parameter;

  $.ajax({
    type: "post",
    url: api.add_jiangjie,
    async: true,
    dataType: 'json',
    cache: false,//上传文件无需缓存        
		processData: false,//使用于对data参数进行序列化解决 这里必需false         
		contentType: false, //必需 
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('上传文件',data);
    // var result = JSON.parse(data);

    var obj = {
      exhibitionhallId: 1,//目前默认二层展厅
      pageNum: 1,
      pageSize: 10
    }
    initCommentary(obj);
    }
    })
}

//配置管理→业务配置→讲解词、语言库配置，AJAX
function ajaxCommentary(pageNum,parameter) {
  //	alert("pageNum："+ pageNum);

  var p = {
    content:{
      exhibitionhallId:1,//目前默认二层展厅
      pageNum:pageNum,
      pageSize:10
    }
  }
  p = JSON.stringify(p);

  console.log('p',p);

  $.ajax({
    type: "post",
    url: api.jiangjie_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      var list = result.content.list;

      jiangjie_list = result.content.list;
      console.log('讲解词list',result);
      var len;
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].productName + '</td>';
        jg += '<td>' + list[i].plateName + '</td>';
        jg += '<td>' + list[i].scriptFileName + '</td>';
        jg += '<td><button class="upload">上传文件</button></td>';
        jg += '<td><input type="file" name="" id="fileUPLoad" accept=".zip"/></td>';//
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableCommentary tbody').html(jg);
    }
  });
}

//配置管理→业务配置→表情库配置，初始化AJAX
function initEmoji(parameter) {

  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.expression_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var dom = $('.emoji .pagination');

      var result = JSON.parse(data);

      console.log('表情库配置',result);

      if(result.content.pages<1){
        $('.tableEmoji tbody').html('');
        return
      }
      startPaginator(dom, result.content.pages,parameter, ajaxEmoji);
    }
  });
}

//配置管理→业务配置→表情库配置，AJAX
function ajaxEmoji(pageNum,parameter) {

  var p={
    content: {
      pageNum:pageNum,
	    pageSize:10,
	    robotId:parameter.robotId
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.expression_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      var list = result.content.list;
      emoji_list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].expressionName + '</td>';
        if(list[i].expressionFileName=='' || list[i].expressionFileName==undefined){
          jg += '<td><button class="uploadEmoji">上传文件</button></td>';
        }else{
          jg += '<td><button class="uploadEmoji">'+ list[i].expressionFileName +'</button></td>';
        }
        
        jg += '<td><input type="file" name="" accept=".zip" id="emojiUPLoad" /></td>';
        if (list[i].isEnable == 1) {
          jg += '<td class="initiate"><button class="active" id="in-use">启用</button></td>';
        } else {
          jg += '<td class="initiate"><button id="out-use">启用</button></td>';
        }
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableEmoji tbody').html(jg);
    }
  });
}
//配置管理→业务配置→表情库配置--上传文件，AJAX
function UpdataExpression(parameter){
  var p = parameter.fileData;

  $.ajax({
    type: "post",
    url: api.update_expression,
    async: true,
    dataType: 'json',
    cache: false,//上传文件无需缓存        
		processData: false,//使用于对data参数进行序列化解决 这里必需false         
		contentType: false, //必需 
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('上传文件',data);
    // var result = JSON.parse(data);

    var obj = {
      pageNum:1,
      pageSize:10,
      robotId:parameter.robotId
    }
    initEmoji(obj);
    }
  })
}
//配置管理→业务配置→表情库配置--启用，AJAX
function enableExpression(parameter){

  var p = {
    content:parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.enable_expression,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('表情库启用',data);
    var result = JSON.parse(data);

    var obj = {
      pageNum:1,
      pageSize:10,
      robotId:parameter.robotId
    }
    initEmoji(obj);

    }
    }) 

}
//配置管理→广告配置→广告播放列表，初始化AJAX
function initADList(parameter) {
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.advertisement_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
     
      var dom = $('.adPlaylist .pagination');

      if(result.content.pages<1) {
        $('.tableADList tbody').html('');
        return;
      }
      startPaginator(dom, result.content.pages,parameter, ajaxADList);
    }
  });
}

//配置管理→广告配置→广告播放列表，AJAX
function ajaxADList(pageNum,parameter) {
  var p={
    content: {
      pageNum:pageNum,
	    pageSize:10,
	    robotId:parameter.robotId
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.advertisement_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      var list = result.content.list;

      console.log('广告列表',result);
      
      ad_list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].adName + '</td>';
        jg += '<td>' + list[i].timeDuration + '</td>';
        if (list[i].isEnable == 1) {
          jg += '<td class="initiate"><button class="active" id="ad_inuse">启用</button></td>';
        } else {
          jg += '<td class="initiate"><button id="ad_inuse">启用</button></td>';
        }
        jg += '<td class="up"></td>';//往上移
        jg += '<td class="down"></td>';//往下移
        jg += '<td class="top"></td>';//置顶
        jg += '<td class="bottom"></td>';//置底
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableADList tbody').html(jg);
    }
  });
}
//配置管理→广告配置→广告播放列表--搜索，AJAX
function searchAdvertisement(parameter){
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.advertisement_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('搜索广告',data);

    var result = JSON.parse(data);

      var list = result.content.list;

      console.log('广告列表',result);
      
      ad_list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].adName + '</td>';
        jg += '<td>' + list[i].timeDuration + '</td>';
        if (list[i].isEnable == 1) {
          jg += '<td class="initiate"><button class="active" id="ad_inuse">启用</button></td>';
        } else {
          jg += '<td class="initiate"><button id="ad_inuse">启用</button></td>';
        }
        jg += '<td class="up"></td>';//往上移
        jg += '<td class="down"></td>';//往下移
        jg += '<td class="top"></td>';//置顶
        jg += '<td class="bottom"></td>';//置底
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableADList tbody').html(jg);

    }
    }) 
}
//配置管理→广告配置→广告启用，AJAX
function enableAdvertisement(parameter){
  var p={
    content: parameter
  }

  p = JSON.stringify(p);  

  $.ajax({
    type: "post",
    url: api.enable_advertisement,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('行业列表',data);
    var result = JSON.parse(data);


    var obj = {
      robotId:parameter.robotId,
      pageNum:1,
      pageSize:10
    }
    initADList(obj);

    }
    }) 

}
//配置管理→广告配置→广告删除，AJAX
function deleteAdvertisement(parameter){
  var p={
    content: {
      adIds:parameter.ids
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.delete_advertisement,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('删除广告',data);
    var result = JSON.parse(data);

    var obj = {
      robotId:parameter.robotId,
      pageNum:1,
      pageSize:10
    }
    initADList(obj);

    }
    })
}
//配置管理→广告配置→广告排序，AJAX
function sortAdvertisement(parameter){
  var p={
    content: parameter
    }
    p = JSON.stringify(p);

    console.log('p',p);
    
    $.ajax({
      type: "post",
      url: api.sort_advertisement,
      async: true,
      dataType: 'text',
      contentType:'application/json;charset=utf-8',
      data:p,
      error: function(xhr) {
      alert('無法取得資料');
      },
      success: function(data) {
      console.log('行业列表',data);
      var result = JSON.parse(data);

      var obj = {
        robotId:parameter.robotId,
        pageNum:1,
        pageSize:10
      }
      initADList(obj);
      }
      })

}
//配置管理→广告配置→广告添加，AJAX
function addAdvertisement(parameter){
  var data=new FormData();
  data.append('content.adName',parameter.adName);
  data.append('adFile',parameter.adFile);

  $.ajax({
    type: "post",
    url: api.add_advertisement,
    async: true,
    dataType: 'json',
    cache: false,//上传文件无需缓存        
		processData: false,//使用于对data参数进行序列化解决 这里必需false         
		contentType: false, //必需 
    data:data,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('添加广告',data);
    // var result = JSON.parse(data);

    var obj = {
      robotId:parameter.robotId,
      pageNum:1,
      pageSize:10
    }
    initADList(obj);
    }
    }) 

}
//配置管理→广告配置→广告触发规则，初始化AJAX
function initADRules(parameter) {

  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.adTriggerrule_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      if(result.content.pages<1){
        $('.tableADRules tbody').html('');
        return;
      }
      var dom = $('.adRules .pagination');
      
      startPaginator(dom, result.content.pages,parameter,ajaxADRules);
    }
  });
}

//配置管理→广告配置→广告触发规则，AJAX
function ajaxADRules(pageNum,parameter) {
  var p={
    content: {
      pageNum:pageNum,
      pageSize:10,
      robotId:parameter.robotId
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.adTriggerrule_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      adRules_list = result.content.list;
      
      console.log('广告触发规则',result);

      var list = result.content.list;
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].ruleName + '</td>';
        jg += '<td>';
        jg += '<select class="selectpicker show-tick form-control editPicker">';
        jg += '<option>5分钟</option>';
        jg += '<option>10分钟</option>';
        jg += '<option>30分钟</option>';
        jg += '<option>无限</option>';
        jg += '</select>';
        jg += '</td>';
        if (data.list[i].isEnable == 1) {
          jg += '<td class="initiate"><button  class="active" id="rule_inuse">启用</button></td>';
        } else {
          jg += '<td class="initiate"><button id="rule_inuse">启用</button></td>';
        }
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableADRules tbody').html(jg);
      //下拉框初始化
      $('.editPicker').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });
    }
  });
}
//配置管理→广告配置→广告触发规则-启用，AJAX
function enableTriggerrule(parameter){
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

$.ajax({
type: "post",
url: api.enable_triggerrule,
async: true,
dataType: 'text',
contentType:'application/json;charset=utf-8',
data:p,
error: function(xhr) {
alert('無法取得資料');
},
success: function(data) {
console.log('行业列表',data);
var result = JSON.parse(data);

var obj = {
  pageNum:1,
  pageSize:10,
  robotId:parameter.robotId
}


initADRules(obj);
}
})
}

//配置管理→广告配置→机器人巡逻路线，初始化AJAX
function initPatrolRoute(parameter) {
  var p={
    content:parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_point,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);

      point_list = result.content.list;

      var list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].productName + '</td>';
        jg += '<td>';
        jg += '<div>选择</div>';
        jg += '<div>x:' + list[i].x +',y:'+ list[i].y+ '</div>';
        jg += '</td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tablePatrolRoute tbody').html(jg);

      // var dom = $('.patrolRoute .pagination');
      // startPaginator(dom,result.content.pages,parameter, ajaxPatrolRoute);
    }
  });
}

//配置管理→广告配置→机器人巡逻路线，AJAX
function ajaxPatrolRoute(pageNum,parameter) {
  var p={
    content:parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.robot_point,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
    }
  });
}

//配置管理→日志、维修、告警配置→日志服务器配置，初始化AJAX
function initServers(parameter) {
  var p = {
    content:{
      pageNum:1,
      pageSize:10
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.server_logo_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      // console.log(JSON.stringify(data, null, 2));

      var result = JSON.parse(data);
      
      if(result.content.pages<1){
        $('.tableServers tbody').html('');
        return;
      }
      var dom = $('.servers .pagination');
      startPaginator(dom,result.content.pages, parameter,ajaxServers);
    }
  });
}

//配置管理→日志、维修、告警配置→日志服务器配置，AJAX
function ajaxServers(pageNum,parameter) {
  var p = {
    content:{
      pageNum:pageNum,
      pageSize:10
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.server_logo_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);

      log_list = result.content.list;

      var list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].serverName + '</td>';
        jg += '<td>' + list[i].serverIp + '</td>';
        if (list[i].isEnable == 1) {
          jg += '<td class="initiate"><button class="active serverInUse">启用</button></td>';
        } else {
          jg += '<td class="initiate"><button class="serverInUse">启用</button></td>';
        }
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableServers tbody').html(jg);
    }
  });
}
//配置管理→日志、维修、告警配置→日志服务器配置--启用，AJAX
function enableRobotLog(parameter){
  var p={
    content: parameter
    }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.enable_serverLogo,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('服务日志启用',data);
    var result = JSON.parse(data);
    }
    })
}
//配置管理→日志、维修、告警配置→告警信息级别配置，初始化AJAX
function initAlarmLevel(parameter) {
  var p = {
    content:{
      pageNum:1,
      pageSize:10
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.level_list,
    async: true,
    dataType: 'text',
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var dom = $('.alarmLevel .pagination');
      var result = JSON.parse(data);

      if(result.content.pages<1){
        $('.tableAlarmLevel tbody').html('');
        return;
      }
      startPaginator(dom,result.content.pages,parameter, ajaxAlarmLevel);
    }
  });
}

//配置管理→日志、维修、告警配置→告警信息级别配置，AJAX
function ajaxAlarmLevel(pageNum,parameter) {
  var p = {
    content:{
      pageNum:pageNum,
      pageSize:10
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.level_list,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));
      var result = JSON.parse(data);
      var list = result.content.list;
      level_list = result.content.list;
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].eventName + '</td>';
        jg += '<td>' + list[i].level + '</td>';
        jg += '<td>' + list[i].reactionTime + '</td>';
        jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }
      //    console.log(jg);jg += '<td><input type="color" name="color" id="" value="#ffffff" disabled="disabled" onblur="chkvalue(this)" /></td>';
      $('.tableAlarmLevel tbody').html(jg);
    }
  });
}
//配置管理→日志、维修、告警配置→告警信息级别配置--删除，AJAX
function deleteLevel(parameter){
  var p={
    content: {
      ids:parameter
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.delete_level,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('告警信息-删除',data);
    var result = JSON.parse(data);

    var obj = {}
    initAlarmLevel(obj);
    }
  }) 


}
//配置管理→日志、维修、告警配置→告警信息级别配置--编辑更新，AJAX
function updataLevel(parameter){
  var p={
    content: {
      list:parameter
    }
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.update_level,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('告警信息-更新',data);
    var result = JSON.parse(data);

    var obj = {}
    initAlarmLevel(obj);
    }
  }) 

}
function addLevel(parameter){
  var p={
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.add_level,
    async: true,
    dataType: 'text',
    contentType:'application/json;charset=utf-8',
    data:p,
    error: function(xhr) {
    alert('無法取得資料');
    },
    success: function(data) {
    console.log('告警信息-更新',data);
    var result = JSON.parse(data);

    var obj = {}
    initAlarmLevel(obj);
    }
  }) 
}
//权限管理  权限列表
function userPurview(parameter) {
  var obj = {
    content: parameter
  }
  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.purview_user,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('权限管理', data);
      var result = JSON.parse(data);

      var list = result.content.list;

      quanxian_list = result.content.list;

      // if(list.length < 1)return;

      var jg = '';

      for (var i = 0; i < list.length; i++) {
        // var num = i + 1;
        jg += '<tr>';
        // jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].robotName + '</td>';
        jg += '<td>';

        var p = list[i];

        for (var j = 0; j < p.purviews.length; j++) {
          var p1 = p.purviews[j];
          jg += '<span>' + p1.roleName + '</span>';
        }
        jg += '</td>';
        jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }
      $('.table-quanxian tbody').html(jg);




    }
  })

}
//权限管理-用户未选择的机器人列表
function purviewUnselectRobot(parameter) {
  var obj = {
    content: parameter
  }
  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.quanxian_user_unselect,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('用户未选择的机器人列表', data);
      var result = JSON.parse(data);

      //
      var list = result.content.list;

      unselect_robot_list = list;

      var len;
      len = list.length;

      var jg = '';

      jg += '<select class="selectpicker show-tick form-control pickRobot">';

      for (var i = 0; i < len; i++) {

        jg += '<option value= ' + list[i].id + '>' + list[i].robotName + '</option>';
      }
      jg += '</select>';

      //编辑权限管理
      $('.permissionModal .model-pickRobot').html(jg);

      //下拉框初始化
      $('.pickRobot').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });


    }
  })

}
//权限管理 角色列表（添加权限用）
function purviewRoleList() {

  var obj = {
    content: {}
  }

  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.purview_role,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('角色列表', data);
      var result = JSON.parse(data);

      var list = result.content.list;

      var jg = '';
      for (var i = 0; i < list.length; i++) {
        jg += '<div>';
        jg += '<input type="checkbox" name="" id="" value="' + list[i].id + '" />';
        jg += '<label for="">' + list[i].roleName + '</label>';
        jg += '</div>'
      }

      $('.permissionModal .check').html(jg);

      //编辑权限
      var bj_qx = '';
      for (var i = 0; i < list.length; i++) {
        bj_qx += '<label class="checkbox-inline">';
        bj_qx += '<input type="checkbox" id="" value="' + list[i].id + '">' + list[i].roleName;
        bj_qx += '</label>';
      }
      $('.permission .control-label .checkbox-bianji').html(bj_qx);

    }
  })

}
//权限管理 添加权限
function addRole(parameter) {
  var obj = {
    content: parameter
  }
  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.quanxian_add,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('添加权限', data);
      var result = JSON.parse(data);

      var p = {
        userId: parameter.userId
      }

      userPurview(p);

    }
  })
}
//权限管理 编辑权限
function updatePurview(parameter) {
  var obj = {
    content: parameter
  }
  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.quanxian_updata,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('编辑权限', data);
      var result = JSON.parse(data);

      var p = {
        userId: parameter.userId
      }

      userPurview(p);

    }
  })
}
//权限管理 删除权限
function deletePurview(parameter) {
  var obj = {
    content: {
      robotUserPurviews: parameter
    }
  }
  obj = JSON.stringify(obj);

  $.ajax({
    type: "post",
    url: api.quanxian_delete,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: obj,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('权限删除', data);
      var result = JSON.parse(data);

      var p = {
        userId: parameter[0].userId
      }

      userPurview(p);
    }
  })

}
/*function ajaxPermission() {
  $.ajax({
    type: "get",
    url: "tableAlarmLevel.json",
    async: true,
    dataType: 'json',
    error: function(xhr) {
      alert('無法取得資料');
    },
    success: function(data) {
      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      for(var i = 0; i < data.list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + data.list[i].name + '</td>';
        jg += '<td>' + data.list[i].level + '</td>';
        jg += '<td>' + data.list[i].time + '</td>';
        jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.tableAlarmLevel tbody').html(jg);
    }
  });
}*/


//监测预警，初始化AJAX
function initMonitor(parameter) {
  var obj = parameter;
  obj.pageNum = 1;
  var p = {
    content: obj
  }
  
  p = JSON.stringify(p);

	$.ajax({
		type: "post",
		url: api.alarm_list,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      // console.log(data);

      var result = JSON.parse(data);
      
      var dom = $('.monitor .pagination');
      if (result.content.pages<1) {
        $('.tableMonitor tbody').html('');
        return;
      }
			startPaginator(dom, result.content.pages, parameter, ajaxMonitor);
		}
	});
}

//监测预警，AJAX
function ajaxMonitor(pageNum, parameter) {
  var obj = parameter;
  obj.pageNum = pageNum;
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

	$.ajax({
		type: "post",
		url: api.alarm_list,
		async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
		data: p,
		error: function(xhr) {
			alert('無法取得資料');
		},
		success: function(data) {
      // console.log(JSON.stringify(data, null, 2));
      
      var result = JSON.parse(data);  

      if(result.content.list.length<1)return;
      var list = result.content.list;

      console.log('监测',list);

			var jg = '';
			for(var i = 0; i < list.length; i++) {
				var num = i + 1;
				jg += '<tr>';
				jg += '<td>' + num + '</td>';
				jg += '<td>' + list[i].robotName + '</td>';
				jg += '<td>' + list[i].receiveDate + '</td>';
				jg += '<td>' + list[i].responsiblePersonName + '</td>';
        jg += '<td>' + list[i].finishDate + '</td>';
        jg += '<td>' + list[i].result + '</td>';
				// if(list[i].status == 0) {
				// 	jg += '<td>待处理</td>';
				// } else if(list[i].status == 1) {
				// 	jg += '<td>进行中</td>';
				// } else {
				// 	jg += '<td>已处理</td>';
				// }
				jg += '</tr>';
			}
			//    console.log(jg);
			$('.tableMonitor tbody').html(jg);
		}
	});
}


//获取预约人
function getAdminuserList() {

  var data = {
    content: {}
  };
  data = JSON.stringify(data);

  $.ajax({
    type: "POST",
    url: api.admin_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: data,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log(data, '预约人列表');

      var result = JSON.parse(data);
      //
      var list = result.content.list;

      admin_list = list;

      var len;
      len = list.length;
      var jg = '';

      jg += '<select class="selectpicker show-tick form-control pickBookingPerson">';

      jg += '<option value="">' +'全部'+ '</option>';
      for (var i = 0; i < len; i++) {

        jg += '<option value="' + list[i].id + '">' + list[i].realName + '</option>';
      }
      
      jg += '</select>';

      console.log(jg, 'jg');

      //预约管理页面
      $('.appointment .showTable .sel .dropdown:nth-child(2)').html(jg);

      $('.pickBookingPerson').selectpicker({
        title: '选择预约人',
        style: 'btn-info',
        size: 4
      });

       // 监测预警页面
       var jc = '';
       jc += '<select class="selectpicker show-tick form-control pickNotifier">';
       jc += '<option value="">全部</option>'

       for(var i = 0; i < len; i++){
         
         jc += '<option value="' + list[i].id + '">' +list[i].realName + '</option>';
       }
       jc += '</select>';
 
       console.log(jc,'jc');
       $('.monitor .notifier').html(jc);
       
       $('.pickNotifier').selectpicker({
         title: '选择预约人',
         style: 'btn-info',
         size: 4
       });

      //权限管理页面

      var qx = '<div for="" class="control-label">选择人员</div>';
      qx += '<select id="pickAdmin-qx" class="selectpicker show-tick form-control pickAdmin" onchange="selectOnchang(this)">';
      for (var i = 0; i < len; i++) {

        qx += '<option value="' + list[i].id + '">' + list[i].realName + '</option>';
      }
      qx += '</select>';

      console.log(qx, 'qx');

      $('.permission .choosePerson .form-group').html(qx);

      $('.pickAdmin').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });


    }
  })
}
//预约管理，展示表格，初始化AJAX
function initAppointmentShow(parameter) {
  var obj = parameter;
  obj.pageNum = 1;
  var p = {
    content: obj
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "POST",
    url: api.record_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('initAppointmentShow', result.content.total, result);

      //    console.log(JSON.stringify(data, null, 2));
      if(result.content.pages<1){
        $('.showTable tbody').html('');
        return;
      }
      var dom = $('.showTable .pagination');
      startPaginator(dom, result.content.pages, parameter, ajaxAppointmentShow);
    }
  });
}

//预约管理，展示表格，AJAX
function ajaxAppointmentShow(pageNum, parameter) {

  var obj = parameter;
  obj.pageNum = pageNum;

  var p = {
    content: obj
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "POST",
    url: api.record_list,
    async: true,
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    data: p,
    error: function (xhr) {
      alert('無法取得資料', xhr);
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('ajaxAppointmentShow', result);

      if (result.content.list.length < 1) return;

      var list = result.content.list;
      //    console.log(JSON.stringify(data, null, 2));
      var jg = '';
      for (var i = 0; i < list.length; i++) {
        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>' + list[i].robotName + '</td>';
        jg += '<td>' + list[i].startTime + '</td>';
        jg += '<td>' + list[i].endTime + '</td>';
        jg += '<td>' + list[i].adminRealName + '</td>';
        jg += '<td>' + list[i].adminTelPhone + '</td>';
        if (list[i].status == 0) {
          jg += '<td>预约中</td>';
        } else if (list[i].status == 1) {
          jg += '<td>接待中</td>';
        } else if (list[i].status == 2) {
          jg += '<td>已接待</td>';
        } else if (list[i].status == 3) {
          jg += '<td>迟到</td>';
        } else if (list[i].status == 4) {
          jg += '<td>未接到</td>';
        } else {
          jg += '<td>已取消</td>';
        }
        /*jg += '<td class="edit"></td>';
        jg += '<td class="delete"></td>';*/
        jg += '</tr>';
      }
      //    console.log(jg);
      $('.showTable tbody').html(jg);
    }
  });
}
//预约管理,2.4.3.1	获取行业列表接口
function getIndustryList() {
  var obj = {
    pageNum: 1,
    pageSize: 100
  }

  var p = {
    content: obj
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.industry_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('行业列表', data);

      var result = JSON.parse(data);

      var list = result.content.list;

      industry_list = result.content.list;

      // pickDepartment
      var len;
      len = list.length;
      var jg = '';

      jg += '<select class="selectpicker show-tick form-control pickDepartment" multiple>';

      for (var i = 0; i < len; i++) {

        jg += '<option value="' + list[i].id + '">' + list[i].name + '</option>';
      }
      jg += '</select>';

      console.log(jg, 'jg');

      $('.appointmentModal .form-row .dropdown:nth-child(4)').html(jg);

      $('.pickDepartment').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });

    }
  })


}
//预约管理,添加新的预约
function addReservation(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.add_reservation,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('新增预约', data);
      var result = JSON.parse(data);

      //预约成功后 获取所有的预约信息 刷新页面
      var data = {};
      setTimeout(initAppointmentShow(data), 500);
    }
  })

}
//预约管理，编辑表格，初始化AJAX
function initAppointmentEdit(parameter) {
  var obj = parameter;
  obj.pageNum = 1;
  var p = {
    content: obj
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.record_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {

      var result = JSON.parse(data);

      console.log('initAppointmentEdit', result.content.total, result);

      if (result.content.pages < 1) return;

      var dom = $('.editTable .pagination');
      startPaginator(dom, result.content.pages, parameter, ajaxAppointmentEdit);

    }
  });
}
//预约管理 预约取消
function cancelReservation(parameter) {
  var p = {
    content: parameter
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.cancel_reservation,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('取消预约', data);
      var result = JSON.parse(data);

      //重新渲染
      // var adminUserId = 17 ;//管理员ID
      // var robotId = 1 ;//机器人ID
      // var startTime ='2018-08-05 14:29';//开始时间
      // var endTime ='2018-10-05 14:29' ;//结束时间
      // var status = 1;//状态

      var adminUserId = $('.appointment .showTable .pickBookingPerson option:selected').val();//管理员ID
      adminUserId = parseInt(adminUserId);

      var robotId = $('.appointment .showTable .pickRobot option:selected').val();//机器人ID
      robotId = parseInt(robotId);

      var startTime = $('.appointment .showTable .sel .start-time').val();//开始时间
      var endTime = $('.appointment .showTable .sel .end-time').val();;//结束时间

      var status = $('.appointment .showTable .pickState option:selected').val();//状态
      status = parseInt(status);

      var data = {
        adminUserId: adminUserId,
        robotId: robotId,
        startTime: startTime,
        endTime: endTime,
        status: status
      }
      initAppointmentEdit(data)
    }
  })
}
//预约管理，编辑表格，AJAX
function ajaxAppointmentEdit(pageNum, parameter) {

  var obj = parameter;
  obj.pageNum = pageNum;

  var p = {
    content: obj
  }
  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.record_list,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      //    console.log(JSON.stringify(data, null, 2));

      var result = JSON.parse(data);

      console.log('ajaxAppointmentEdit', result);

      if (result.content.list.length < 1) return;

      var list = result.content.list;

      var ary = [];
      for (var a = 0; a < list.length; a++) {
        var obj = list[a];
        if (obj.status == 0) {
          ary.push(obj);
        }
      }

      list = ary;

      order_list = ary;//只包含执行中的预约

      var jg = '';


      for (var i = 0; i < list.length; i++) {

        var num = i + 1;
        jg += '<tr>';
        jg += '<td>' + num + '</td>';
        jg += '<td>';
        jg += '<select class="selectpicker show-tick form-control editPicker ">';
        for (var j = 0; j < robot_list.length; j++) {
          if ( robot_list[j].id == list[i].robotId) {

            jg += '<option selected="selected" value=' + robot_list[j].id + '>' + robot_list[j].robotName + '</option>';

          } else {
            jg += '<option value=' + robot_list[j].id + '>' + robot_list[j].robotName + '</option>';
          }
        }
        jg += '</select>';
        jg += '</td>';
        jg += '<td>';
        jg += '<input type="text" value=' + list[i].startTime + ' class="datetimepicker now bianji_start">';
        jg += '</td>';
        jg += '<td>';
        jg += '<input type="text" value=' + list[i].endTime + ' class="datetimepicker">';
        jg += '</td>';
        jg += '<td>';
        // jg +=   '<td>' + list[i].adminTelPhone + '</td>';
        jg += '<select class="selectpicker show-tick form-control editPicker bianji_admin">';
        for (var m = 0; m < admin_list.length; m++) {
          if (list[i].adminRealName == admin_list[m].realName) {

            jg += '<option selected="selected" value=' + admin_list[m].id + '>' + admin_list[m].realName + '</option>';

          } else {
            jg += '<option value=' + admin_list[m].id + '>' + admin_list[m].realName + '</option>';
          }
        }
        jg += '</select>';
        jg += '</td>';
        jg += '<td>' + list[i].adminTelPhone + '</td>';
        jg += '<td class="delete"></td>';
        jg += '<td><input type="checkbox" name="" id="" value="" /></td>';
        jg += '</tr>';
      }

      //    console.log(jg);
      $('.editTable tbody').html(jg);
      //日期控件初始化
      $('.datetimepicker').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        language: 'zh-CN',
        weekStart: 1,
        todayBtn: true,
        autoclose: 1,
        todayHighlight: true,
        startView: 2,
        minView: 0, //日期时间选择器所能够提供的最精确的时间选择视图。
        minuteStep: 10, //此数值被当做步进值用于构建小时视图。
        //      initialDate:
        //      forceParse: 0
      });
      //下拉框初始化
      $('.editPicker').selectpicker({
        title: '请选择',
        style: 'btn-info',
        size: 4
      });
    }
  });
}
//预约管理，编辑保存表格，AJAX
function ajaxAppointmentSave(parameter) {
  var p = {
    content: {
      list: parameter
    }
  }

  p = JSON.stringify(p);

  $.ajax({
    type: "post",
    url: api.save_reservation,
    async: true,
    dataType: 'text',
    contentType: 'application/json;charset=utf-8',
    data: p,
    error: function (xhr) {
      alert('無法取得資料');
    },
    success: function (data) {
      console.log('编辑保存', data);
      var result = JSON.parse(data);

      var p = {};
      initAppointmentShow(p);

    }
  })
}

/*AJAX数据加载方法↑*/

//test

  //驱动左下滚动效果
/*  jQuery(".txtMarquee-top").slide({
    mainCell: ".bd ul",
    autoPlay: true,
    effect: "topMarquee",
    vis: 2,
    interTime: 50
  });*/